//document.write(`<script src="${_js_dir_host}js/view/login/tools.js" type="text/javascript" charset="utf-8"></script>`);

define(["request"], function(request) {
	var bindObj = {};
	//获取验证码入口
	/*
	 *phone
	 *access_token 为空为默认系统会设置
	 * is_new :true ,新人，需要从未绑定，false：老人，需要已经绑定过
	 * */
	bindObj.OnVerify = function(phone,access_token,is_new,successFun) {
		var wt = plus.nativeUI.showWaiting(null, {
			back: "none"
		});
		var mask = mui.createMask();
		mask.show(); //显示遮罩	
		request.requestAjax("post", "go/verify", {
			phone: phone,
			access_token:access_token,
			is_new:is_new
		}, function(res) {
			wt.close();
			mask.close();
			console.log(JSON.stringify(res))
			if(res.state == true) {
				successFun(res.data);
			} else {
				mui.toast(res.error)
			}
		}, function(res) {
			wt.close();
			mask.close();
			mui.toast("网络错误,请检查网络连接")
			console.log(JSON.stringify(res))
		})
	}
	
	//绑定手机号
	bindObj.OnBindPhone = function(phone,verify,successFun) {
		var wt = plus.nativeUI.showWaiting(null, {
			back: "none"
		});
		request.OnAjax("post", "bind_phone", {
			phone: phone,
			verify:verify
		}, function(data) {
			wt.close();
			successFun(data);
		}, function(res) {
			wt.close();
		})
	}
	
	//获取ocr信息
	bindObj.OnGetOcrInfo = function(url,successFun) {
		var wt = plus.nativeUI.showWaiting(null, {
			back: "none"
		});
		request.OnAjax("post", "ocr/check", {
			url: url,
		}, function(data) {
			wt.close();
			successFun(data);
		}, function(res) {
			wt.close();
		});
	}
	
	//绑定信息
	bindObj.OnBindOcr = function(open_id,type,id_card,successFun) {
		var wt = plus.nativeUI.showWaiting(null, {
			back: "none"
		});
		request.OnAjax("post", "ocr/bind", {
			open_id: open_id,
			type: type,
			id_card: id_card
		}, function(data) {
			wt.close();
			successFun(data)
		}, function(res) {
			wt.close();
		});
	}
	
	//绑定信息
	bindObj.OnGetUserByPhoto = function(id_card,successFun) {
		var wt = plus.nativeUI.showWaiting(null, {
			back: "none"
		});
		request.OnAjax("post", "getuserbyphoto", {
			id_card: id_card
		}, function(data) {
			wt.close();
			successFun(data)
		}, function(res) {
			wt.close();
		});
	}
	
	//通过手机号获取用户信息
	bindObj.OnGetUserByPhone = function(phone,verify,access_token,successFun) {
		var wt = plus.nativeUI.showWaiting(null, {
			back: "none"
		});
		request.OnAjax("post", "getuserbyphone", {
			phone: phone,
			verify:verify,
			access_token:access_token
		}, function(data) {
			wt.close();
			successFun(data);
		}, function(res) {
			wt.close();
		})
	}
	

	return bindObj;
})